package com.ts.main.admin.controller;
import com.ts.main.admin.dto.MiniRoleDto;
import com.ts.main.admin.dto.MiniRoleSearchPageDto;
import com.ts.main.admin.exception.R;
import com.ts.main.admin.exception.RPage;
import com.ts.main.admin.service.RoleServiceImpl;
import com.ts.main.admin.vo.MiniRoleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:lk
 * @Date: 2025/6/11  23:25
 */
@AllArgsConstructor
@RestController
@RequestMapping("/miniRole")
@Tag(name = "小程序管理-角色管理")
public class MiniRoleController {

    private final RoleServiceImpl roleService;

    @PostMapping("/getMiniRoleList")
    @Operation(summary = "查询角色列表")
    public RPage<List<MiniRoleVo>> getMiniRolePage(@RequestBody MiniRoleSearchPageDto dto) {
        return roleService.getMiniRolePage(dto);
    }

    @GetMapping("/getMiniRoleDetails")
    @Operation(summary = "查询角色详情")
    public R<MiniRoleVo> getMiniRoleDetails(@Schema(description = "角色ID") @RequestParam Integer roleId) {
        return R.ok(roleService.getMiniRoleDetails(roleId));
    }

    @PostMapping("/saveMiniRole")
    @Operation(summary = "添加角色")
    public R<MiniRoleDto> saveMiniRole(@RequestBody MiniRoleDto dto) {
        return R.ok(roleService.saveMiniRole(dto));
    }

    @PutMapping("/updateMiniRole")
    @Operation(summary = "修改角色")
    public R<Boolean> updateMiniRole(@RequestBody MiniRoleDto dto) {
        return R.ok(roleService.updateMiniRole(dto));
    }

    @DeleteMapping("/deleteMiniRole")
    @Operation(summary = "删除角色")
    public R<Boolean> deleteMiniRole(@Schema(description = "角色ID") @RequestParam Integer roleId) {
        return R.ok(roleService.deleteMiniRole(roleId));
    }

}